<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <!-- <script>
        function delay(ms) {
            return new Promise((resolve, reject) => {
                setTimeout(resolve, ms)
            })
        }
        const { body } = document
        async function lights() {
            body.style.backgroundColor = 'red'
            await delay(3000)
            body.style.backgroundColor = 'yellow'
            await delay(1000)
            body.style.backgroundColor = 'green'
            await delay(1000)
            body.style.backgroundColor = 'yellow'
            await delay(1000)
            lights()
            return delay(0)
            // .then(() => body.style.backgroundColor = 'red')
            // .then(() => delay(3000))
            // .then(() => body.style.backgroundColor = 'yellow')
            // .then(() => delay(1000))
            // .then(() => body.style.backgroundColor = 'green')
            // .then(() => delay(3000))
            // .then(() => body.style.backgroundColor = 'yellow')
            // .then(() => delay(1000))
            // .then(() => lights())
        }
        lights()
    </script> -->
    <script>
        function delay(ms) {
            return new Promise((resolve, reject) => {
                setTimeout(resolve, ms)
            })
        }
        function ajax(data, ms) {
            return delay(ms).then(() => data)
        }
        const beige = Date.now()
        async function fn() {
            let d1 = ajax("a", 1000)
            let d2 = ajax("b", 500)
            let d3 = ajax("c", 1500)
            let p1 = await d1
            let p2 = await d2
            let p3 = await d3
            console.log(p1, p2, p3, (Date.now() - beige) / 1000);
        }
        fn()
    </script>
</body>

</html>